<?php

/**
 * facturas form.
 *
 * @package    gescell
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class facturasForm extends BasefacturasForm
{
  public function configure()
  {      
      $this->widgetSchema['clientes_id'] = new sfWidgetFormChoice(array(
         'choices'          => array(),
         'renderer_class'   => 'sfWidgetFormPropelJQueryAutocompleter',
         'renderer_options' => array(
         'model'            => 'clientes',
         'url'              => $this->getOption('url')
    )
    ));
      $this->widgetSchema['fecha']  = new sfWidgetFormJQueryDate(array(
          'format' =>  '%day%/%month%/%year%'
      ));
      
      $this->widgetSchema['clientes_id']->setattribute('size', '50');
      $this->widgetSchema['clientes_id']->setattribute('class' ,'text ui-widget-content ui-corner-all');
      $this->widgetSchema['numero_de_comprobante']->setattribute('size', '50');
      $this->widgetSchema['numero_de_comprobante']->setattribute('class' ,'text ui-widget-content ui-corner-all');

     //Embebido
      /*
      $facturadetalle = $this->getObject()->getfacturadetalles();
    //Embeber un detalle al menos
      if (!$facturadetalle){
            $detalle = new facturadetalle();
            $detalle->setFacturas($this->getObject());
            $facturadetalle = array($detalle);
        }
        $detalles_forms = new sfForm();
        $count = 0;
        foreach ($facturadetalle as $detalle) {
            $detall_form = new facturadetalleForm($detalle);
            //Empotramos cada formulario en el contenedor
            $detalles_forms->embedForm($count, $detall_form);
            $count ++;
        }
        //$this->setwidget(array('total') , array('disabled' => false));
        $this->embedForm('detalles', $detalles_forms);
       * Aca termina el Comentado
       */
}
public function addfacturadetalle($num){
         $det = new facturadetalle();
         $det->setfacturas($this->getObject());
        
        
        $det_form = new facturadetalleForm($det);
        //Empotramos la nueva p�cture en el contenedor
        $this->embeddedForms['detalles']->embedForm($num, $det_form);
        //Volvemos a empotrar el contenedor
        $this->embedForm('detalles', $this->embeddedForms['detalles']);
    }

public function isValid(){
    if ($this['anulado']->getvalue())
        return false;
    else
        return parent::isValid();
}


/* public function bind(array $taintedValues = null, array $taintedFiles = null)
    {
      foreach($taintedValues['detalles'] as $key=>$nuevoDetalle)
      {
        if (!isset($this['detalles'][$key]))
        {
          $this->addfacturadetalle($key);
        }
      }
      parent::bind($taintedValues, $taintedFiles);
}*/
}